//*****************************************************************************
// pid.h - Prototypes for the PID feedback control algorithm.


#ifndef __PID_H__
#define __PID_H__


// This structure contains the internal state of the PID algorithm.
typedef struct
{
    //
    // The current value of the integrator.
    //
    long lIntegrator;

    //
    // The maximum allowable value of the integrator.
    //
    long lIntegMax;

    //
    // The minimum allowable value of the integrator.
    //
    long lIntegMin;

    //
    // The error from the previous call to the algorithm.  This is used for
    // determining the derivative of the error.
    //
    long lPrevError;

    //
    // The proportional gain factor.
    //
    long lPGain;

    //
    // The integral gain factor.
    //
    long lIGain;

    //
    // The derivative gain factor.
    //
    long lDGain;
}
tPIDState;


// PID module function prototypes.
extern void PIDInitialize(tPIDState *psState, long lIntegMax, long lIntegMin,
                          long lPGain, long lIGain, long lDGain);
extern void PIDGainPSet(tPIDState *psState, long lPGain);
extern void PIDGainISet(tPIDState *psState, long lIGain, long lIntegMax,
                        long lIntegMin);
extern void PIDGainDSet(tPIDState *psState, long lDGain);
extern void PIDReset(tPIDState *psState);
extern long PIDUpdate(tPIDState *psState, long lError);



#endif // __PID_H__
